package com.activititest.controller;

import com.activititest.appentity.Response;
import com.activititest.entity.EmTaskCommitForm;
import com.activititest.entity.EmTaskCommitPulltant;
import com.activititest.entity.ParameterCmd;
import com.activititest.service.IEmTaskCommitFormService;
import com.activititest.service.IEmTaskCommitPulltantService;
import com.activititest.service.OrdinaryUsersServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@RestController
@RequestMapping("/userordinary")
public class UsersOrdinaryController {
    @Autowired
    private OrdinaryUsersServer ordinaryUsersServer;
    @Autowired
    private IEmTaskCommitFormService iEmTaskCommitFormService;
    @Autowired
    private IEmTaskCommitPulltantService iEmTaskCommitPulltantService;
    @PostMapping("/findtask/")
    public void findTask(@RequestBody String area){
        System.out.println(area+"op==============================");
        ordinaryUsersServer.findTasks(area);
    }
    @PostMapping("/commotTask/")
    public Response<String> commotTask(@RequestParam("enterprise_id") String enterprise_id,@RequestParam("task_id") String task_id,@RequestBody List<EmTaskCommitPulltant> emTaskCommitPulltants){
//        System.out.println(enterprise_id+"=============================="+task_id+"=========="+emTaskCommitPulltants.size());
        String aftertaskid = ordinaryUsersServer.CommitTaskss(task_id);
        EmTaskCommitForm emTaskCommitForm = new EmTaskCommitForm();
        emTaskCommitForm.setEnterpriseId(Integer.parseInt(enterprise_id));
        emTaskCommitForm.setTaskId(aftertaskid);
        emTaskCommitForm.setCommitFormDatetime(LocalDateTime.now());
        iEmTaskCommitFormService.save(emTaskCommitForm);
        for(int i=0;i<emTaskCommitPulltants.size();i++){
            emTaskCommitPulltants.get(i).setTaskId(aftertaskid);
        }
        iEmTaskCommitPulltantService.saveBatch(emTaskCommitPulltants);
        Response euserResponse = new Response();
        euserResponse.setCode(200);
        euserResponse.setData("yes");
        euserResponse.setMsg("yes");
        return euserResponse;
    }
}
